﻿using System;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Texfina.Core.Web;
using System.Text;
using Texfina.Core.Common;
using Texfina.Entity.Co;
using Texfina.BOQry.Co;

using System.Collections;
using System.Data;
using System.IO;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Drawing.Printing;
using System.Globalization;

namespace CO
{
    public partial class wfExportacionesMnt : PageBase
    {        
        public override void RegisterGeneralScripts()
        {

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("var varRet = modalDialog('wfExportaciones.aspx',750,400);");
            sb.AppendLine("if(varRet==null)");
            sb.AppendLine("return false;");
            sb.AppendLine("ctl = document.getElementById('" + this.hdnidExportacion.ClientID + "');");
            sb.AppendLine("ctl.value = varRet[1];");
            sb.AppendLine("ctl = document.getElementById('" + this.txtidExportacion.ClientID + "');");
            sb.AppendLine("ctl.value = varRet[1];");
            sb.AppendLine("ctl = document.getElementById('" + this.txtDescripcion.ClientID + "');");
            sb.AppendLine("ctl.value = varRet[2];");
            this.txtidExportacion.OnClientClick = sb.ToString();

            ScriptManager.RegisterStartupScript(this, this.GetType(), "ScriptRegister", sb.ToString(), true);

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsCallback) return;
            if (!Page.IsPostBack)
            {
                this.LoadInPostBack();
                LoadData();
                return;
            }
        }

        public override void LoadInPostBack()
        {
            this.RegisterGeneralScripts();
        }

        private void LoadData()
        {
            btnNuevo.ImageUrl = Constants2.ConstMenuControlValue.BUTTON_NEW;
            btnGrabar.ImageUrl = Constants2.ConstMenuControlValue.BUTTON_SAVENEW;
            btnSalir.ImageUrl = Constants2.ConstMenuControlValue.BUTTON_EXIT;
            WebHelper.LoadListControl2(dpTipTerminos, BTablaGeneral.TablaGeneralFill("135"), "ds_item", "id_item");
            WebHelper.LoadListControl2(dpEmbarque, BTablaGeneral.TablaGeneralFill("134"), "ds_item", "id_item");
        }

        protected void btnNuevo_Click(object sender, ImageClickEventArgs e)
        {
            txtidExportacion.Text = "";
            txtDescripcion.Text = "";
        }

        protected void btnGrabar_Click(object sender, ImageClickEventArgs e)
        {
            Eexportacion prov = new Eexportacion();

            DropDownList idImp = new DropDownList();
            if (txtidExportacion.Text == "")
            {
                WebHelper.LoadListControl2(idImp, BExportacion.Exportacion_qry01(Session[ConstSessionVar.PERIODO].ToString(), Session[ConstSessionVar.EMPRESA].ToString()), "id_Exportacion", "id_Exportacion");
                hdnidExportacion.Value = idImp.SelectedItem.Text;
                prov.Id_Exporta = hdnidExportacion.Value;
                prov.Id_Empresa = Session[ConstSessionVar.EMPRESA].ToString();
            }
            else
            {
                prov.Id_Exporta = txtidExportacion.Text;
                prov.Id_Empresa = Session[ConstSessionVar.EMPRESA].ToString();
            }
            prov.Ds_Exporta = txtDescripcion.Text.ToUpper();
            prov.Id_via = dpEmbarque.SelectedValue;
            prov.Id_tercom = dpTipTerminos.SelectedValue;
            prov.Id_ucrearec = Session[ConstSessionVar.IDLOGON].ToString();
            prov.Id_uupdarec = Session[ConstSessionVar.IDLOGON].ToString();
            BExportacion.Exportacion_mnt01(prov);

            //lblMensaje.Text = "Datos Grabados";
            txtidExportacion.Text = hdnidImportacion.Value;
        }

    }
}